package com.kate.mall.bff.wx.controller;

import com.kate.mall.common.utils.R;
import com.kate.mall.common.utils.R;
import com.kate.mall.bff.wx.controller.form.WxLoginForm;
import com.kate.mall.bff.wx.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Description: 用一句话描述
 * @Auther: 新梦想*陈超
 * @Date: 2021/11/1 11:35
 */
@RestController
@RequestMapping("wx/auth")
@Slf4j
public class LoginController {

    @Resource
    private LoginService loginService;

    @PostMapping("/login_by_weixin")
    public R loginByWeixin(@RequestBody WxLoginForm wxLoginForm, HttpServletRequest request) throws WxErrorException {

        R tokenR = loginService.loginByWeixin(wxLoginForm,request);//www.mosoteach.cn/web/index.php?c=interaction_homework&m=homework_result_list&clazz_course_id=CE7D7EC6-7477-41D6-8A48-B4933769C3D9&id=17C3632B-B66A-0E28-1B6E-A75C13EF7B74&order_item=group&operater_id=A92D656B-A8C7-4126-A4D5-159E132ABECF&status=IN_PRGRSeixin(wxLoginForm,request);
        return tokenR;
    }

    @PostMapping("/logout")
    public R logout(@RequestBody WxLoginForm wxLoginForm) throws WxErrorException {

        R tokenR = loginService.logout(wxLoginForm);
        return tokenR;
    }





}
